﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace List功能测试
{
    class cc
    {
        public int num;
        public string cap;
    }

    class Program
    {

        static void Main(string[] args)
        {
            List<cc> cclist = new List<cc>();

            cclist = GetList();
            var li = cclist.Where(o => o.num == 5).ToList();
            if (li.Count > 0) li[0].cap = "5555";
            Console.WriteLine("num:" + cclist[5].num.ToString());
            Console.WriteLine("cap:" + cclist[5].cap);

            Console.WriteLine("**************************************");
            List<cc> list = new List<cc>();
            list.Add(new cc() { num = 1, cap = "1"});
            list.Add(new cc() { num = 2, cap = "2" });
            list.Add(new cc() { num = 3, cap = "3" });
            list.Add(new cc() { num = 4, cap = "4" });
            list.Add(new cc() { num = 5, cap = "5" });

            Console.WriteLine("**************   first test ! ***************");
            Console.WriteLine(list.First().num);
            Console.WriteLine(list.First().num);
            Console.WriteLine(list.First().num);

            Console.WriteLine("**************   first test end !  **********");

            int cnt = list.Count-1;
            for (int i=cnt;i>=0;i--) {
                Console.WriteLine(list[i].cap);
                list.RemoveAt(i);
            }

            Console.WriteLine("余数：" + list.Count.ToString());

            Console.ReadLine();
        }

        public static List<cc> GetList()
        {
            List<cc> cclist = new List<cc>();

            for(int i=0;i<10;i++)
            {
                cc c = new cc();
                c.num = i;
                c.cap = "cap" + i.ToString();
                cclist.Add(c);
            }

            return cclist;
        }
    }
}
